<?php
declare (strict_types = 1);

namespace app\admin\controller;
use app\admin\model\AdminConfig;
use think\facade\Db;
use think\facade\View;
use think\facade\Env;
use think\facade\Config;

class Index extends  Base
{
    function index()
    {
        $menus = [];
        $where = ['group_id'=>$this->user['group_id']];
        $role = Db::table('admin_user_group')->where($where)->find(); //根据用户group_id获取数据表admin_user_group的内容
        if($role){
            $role['rights'] = (isset($role['rights']) && $role['rights']) ? json_decode($role['rights'],true) : [];
        }

        //组合一个where条件，要求：smid在数组中，status=1两个条件
        if($role['rights']){
            $where = [
                ['smid','in',implode(',',$role['rights']) ],
                ['status','=',1]
            ];
            $menus = Db::table('admin_sys_menu')->order('type,sort desc')->where($where)->select();
            foreach($menus as $menus_v){
                if($menus_v['parent_id'] == 0){
                    $menu[$menus_v['smid']] = $menus_v;
                }else{
                    $menu[$menus_v['parent_id']]['children'][] = $menus_v;
                }
            }
        }
        View::assign([
            'role' => $role,
            'menu' => $menu
        ]);
        return View::fetch();
    }

    # 欢迎页面
    public function welcome(){
        View::assign([
            'time' => date('Y-m-d',$_SERVER['REQUEST_TIME']),
        ]);
        return View::fetch();
    }
}
